package com.rndemo.rn;

import com.facebook.react.LazyReactPackage;
import com.facebook.react.bridge.ModuleSpec;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.model.ReactModuleInfoProvider;
import com.rndemo.rn.api.NavigationModule;
import com.rndemo.rn.api.PlatformApi;
import com.rndemo.rn.api.SqliteModule;
import com.rndemo.rn.view.RecyclerView.RnRecyclerViewManage;
import com.rndemo.rn.view.RnListViewManager;
import com.rndemo.rn.view.RnFrameLayoutManager;
import com.rndemo.rn.view.RnRefreshLayoutManager;

import java.util.Arrays;
import java.util.List;

import javax.inject.Provider;

/**
 * Created by tzj on 2018/3/27.
 */
public class MyPackage extends LazyReactPackage {
    @Override
    public List<ModuleSpec> getNativeModules(final ReactApplicationContext reactContext) {
        return Arrays.asList(
                ModuleSpec.nativeModuleSpec(
                        PlatformApi.class,
                        new Provider<NativeModule>() {
                            @Override
                            public NativeModule get() {
                                return new PlatformApi();
                            }
                        }),
                ModuleSpec.nativeModuleSpec(
                        NavigationModule.class,
                        new Provider<NativeModule>() {
                            @Override
                            public NativeModule get() {
                                return new NavigationModule(reactContext);
                            }
                        }),
                ModuleSpec.nativeModuleSpec(
                        SqliteModule.class,
                        new Provider<NativeModule>() {
                            @Override
                            public NativeModule get() {
                                return new SqliteModule();
                            }
                        }));
    }
    @Override
    public List<ModuleSpec> getViewManagers(ReactApplicationContext reactContext) {
        return Arrays.asList(
                ModuleSpec.nativeModuleSpec(
                        RnListViewManager.class,
                        new Provider<NativeModule>() {
                            @Override
                            public NativeModule get() {
                                return new RnListViewManager();
                            }
                        }),
                ModuleSpec.nativeModuleSpec(
                        RnRecyclerViewManage.class,
                        new Provider<NativeModule>() {
                            @Override
                            public NativeModule get() {
                                return new RnRecyclerViewManage();
                            }
                        }),
                ModuleSpec.nativeModuleSpec(
                        RnFrameLayoutManager.class,
                        new Provider<NativeModule>() {
                            @Override
                            public NativeModule get() {
                                return new RnFrameLayoutManager();
                            }
                        }),
                ModuleSpec.nativeModuleSpec(
                        RnRefreshLayoutManager.class,
                        new Provider<NativeModule>() {
                            @Override
                            public NativeModule get() {
                                return new RnRefreshLayoutManager();
                            }
                        }));
    }
    @Override
    public ReactModuleInfoProvider getReactModuleInfoProvider() {
        return LazyReactPackage.getReactModuleInfoProviderViaReflection(this);
    }
}
